<%--
  Created by IntelliJ IDEA.
  User: 李元峰
  Date: 2022/10/20
  Time: 10:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set value="${pageContext.request.contextPath}" var="path"></c:set>
<table class="table table-hover align-middle">
<tbody>
<tr>
    <td>
        <input type="checkbox" class="form-check-input select_one" id="checkAll">
    </td>
    <td>
        本页全选
    </td>
</tr>
<c:forEach items="${requestScope.notices.list}" var="notice">
    <tr>
        <td>
            <input type="checkbox" class="form-check-input select_one check_one" data-id="${notice.id}">
        </td>
        <td style="width: 75%;">
            <div class="pxp-dashboard-notifications-item-left">
                <div class="pxp-dashboard-notifications-item-type"><c:if test="${notice.reader}" var="isReading"><span class="fa fa-briefcase" ></span></c:if> <c:if test="${not isReading}"><span class="fa fa-envelope-o notReading"></span></c:if> </div>
                <div class="pxp-dashboard-notifications-item-message">
                    <a href="/web/personal/personalCompanyDetail/${notice.company.id}">${notice.company.name}</a> ${notice.noticeMode.noticeInfo}
                </div>
            </div>
        </td>
        <td style="width: 20%;"><div class="pxp-dashboard-notifications-item-right" id="notice_time${notice.id}"></div></td>
        <td>
            <div class="pxp-dashboard-table-options">
                <ul class="list-unstyled">
                    <c:if test="${not notice.reader}"><li><button title="标记已读" class="reading" id="read${notice.id}"><span class="fa fa-eye"></span></button></li></c:if>
                    <li><button title="删除" class="deleteNotice" id="del${notice.id}"><span class="fa fa-trash-o"></span></button></li>
                </ul>
            </div>
        </td>
        <input type="hidden" class="notice_time" value="<fmt:formatDate value='${notice.noticeTime}' pattern='yyyy-MM-dd HH:mm:ss'/>"/>
    </tr>
</c:forEach>
</tbody>
</table>
<div class="row mt-4 mt-lg-5 justify-content-between align-items-center">
    <div class="col-auto" style="margin: auto;">
        <nav class="mt-3 mt-sm-0" aria-label="Notifications pagination">
            <ul class="pagination pxp-pagination">
                <li class="page-item"><a class="page-link lastPage" href="#">上一页</a></li>
                <c:forEach items="${requestScope.notices.navigatepageNums}" var="i">
                    <c:if test="${i==requestScope.notices.pageNum}" var="nowPage">
                        <li class="page-item active" aria-current="page">
                            <span class="page-link">${i}</span>
                        </li>
                    </c:if>
                    <c:if test="${not nowPage}">
                        <li class="page-item"><a class="page-link changePage" href="#">${i}</a></li>
                    </c:if>
                </c:forEach>
                <li class="page-item"><a class="page-link nextPage" href="#">下一页</a></li>
            </ul>
        </nav>
    </div>
</div>
<input type="hidden" value="${requestScope.numOfNotice}" id="numNotice"/>


<script src="/static/web/js/jquery-3.4.1.min.js"></script>
<script>
    $(function (){
        $(".notice_time").each(function (){
           let noticeTime = $(this).val();
            let nowTime = new Date().getTime();
            let oldTime = new Date(noticeTime).getTime();
            let time = nowTime - oldTime;
            let minute = parseInt(time/1000/60%60);
            let hour = parseInt(time/1000/60/60%24);
            let day = parseInt(time/1000/60/60/24%30);
            let info = "";
            if (minute<1&&hour<1&&day<1)
            {
                info = "刚刚";
                $(this).prev().prev().html(info);
                return;
            }
            info = "前"
            if (minute>=1) {
                info = minute + "分钟" +info;
            }
            if (hour>=1)
            {
                info = hour+"小时"+info;
            }
            if (day>=1)
            {
                info = day+"天"+info;
            }
            $(this).prev().prev().html(info);
        });
    });
</script>
